﻿namespace ChessToys
{
    using System;
    using System.Collections.Generic;

    public class KnightMoveGenerator : AbstractPieceMoveGenerator<Knight>
    {
        protected override ISet<Move> GenerateForSpecificPiece(Board board, Position start, Knight piece)
        {
            // prepare moves
            ISet<Move> moves = new HashSet<Move>();
            // up up right
            moves.UnionWith(Crawl(board, start, new Position(1, -2), new Position(start.X + 2, start.Y - 3)));
            // up up left
            moves.UnionWith(Crawl(board, start, new Position(-1, -2), new Position(start.X - 2, start.Y - 3)));
            // right right up
            moves.UnionWith(Crawl(board, start, new Position(2, -1), new Position(start.X + 3, start.Y - 2)));
            // right right down
            moves.UnionWith(Crawl(board, start, new Position(2, 1), new Position(start.X + 3, start.Y + 2)));
            // down down right
            moves.UnionWith(Crawl(board, start, new Position(1, 2), new Position(start.X + 2, start.Y + 3)));
            // down down left
            moves.UnionWith(Crawl(board, start, new Position(-1, 2), new Position(start.X - 2, start.Y + 3)));
            // left left up
            moves.UnionWith(Crawl(board, start, new Position(-2, -1), new Position(start.X - 3, start.Y - 2)));
            // left left down
            moves.UnionWith(Crawl(board, start, new Position(-2, 1), new Position(start.X - 3, start.Y + 2)));
            // return moves
            return moves;
        }
    }
}
